package tree;
import java.util.*;
import java.io.*;

public class Tree {
		
	public void printTree(String folderName, int nest){
		
		File folder = new File(folderName);
		if (!folder.exists()){
			System.out.println("Directory not found: " + folderName);			
		} else{
			StringBuilder gap = new StringBuilder();
			for (int i = 0; i < nest; i++){
				gap.append(' ');
			}
			File[] list = folder.listFiles();
			
			for(File file : list){
				if(file.isDirectory()){
					System.out.println(gap.toString() + "[+]" + file.getName());
					printTree(file.toString(), nest+1);
				} else {System.out.println(gap.toString() + file.getName());}
			}
		}
	}
							
		
	public static void main(String[] args) {
		Tree tree = new Tree();
		Scanner scn = new Scanner(System.in);
		System.out.println("Enter the path...");
		String folderName = scn.nextLine();
		System.out.println("Tree of directory...");
		tree.printTree(folderName, 0);
	}
}
